﻿using System;
using System.Windows.Controls;
using static HomagChina.CCHCS.Views.JobList;

namespace HomagChina.CCHCS.Views
{
    /// <summary>
    /// BoardLibrary.xaml 的交互逻辑
    /// </summary>
    public partial class BoardLibrary : UserControl
    {
        private double HomeBatchDetailVerticalOffset;

        public BoardLibrary()
        {
            InitializeComponent();
        }

        public void ViewModel_RequestScrollPositionSave(object sender, EventArgs e)
        {
            SaveScrollPosition();
        }

        public void ViewModel_RequestScrollPositionRestore(object sender, EventArgs e)
        {
            RestoreScrollPosition();
        }

        private void SaveScrollPosition()
        {
            var BatchDetailscrollViewer = VisualTreeHelperExtensions.FindVisualChild<ScrollViewer>(BoardLibraryTable);
            if (BatchDetailscrollViewer != null)
            {
                HomeBatchDetailVerticalOffset = BatchDetailscrollViewer.VerticalOffset;
            }
        }

        private void RestoreScrollPosition()
        {
            var BatchDetailscrollViewer = VisualTreeHelperExtensions.FindVisualChild<ScrollViewer>(BoardLibraryTable);
            BatchDetailscrollViewer?.ScrollToVerticalOffset(HomeBatchDetailVerticalOffset);
        }
    }
}